if ARGV.size<=0
	exit 1
end
in_file =File.open ARGV[0]
#读取文件中的第一行
require_statement = in_file.readline  
#puts require_statement
#获取双引号中间的字符串
if require_statement =~ /"(.*)"/
	file_path = $1
else
	#获取单引号之间的字符串
	if require_statement =~ /'(.*)'/
		file_path = $1
	else
		#获取失败,返回1
		exit 1
	end
end

is_relative = false
begin
	#尝试加载库
	require file_path
rescue LoadError =>err
	begin
		#系统路径加载失败,从当前目录尝试加载库
		require_relative file_path
		is_relative = true
	rescue LoadError =>err
		exit 1
	end
end
#puts "find the file"
def out_path path
	print path
end

if is_relative #如果是相对目录,则在当前目录下寻找
	curr_dir = File.dirname(__FILE__)
	new_path = "#{curr_dir}/#{file_path}.rb"
	if File.exist? new_path
		out_path new_path
		exit 0  #找到返回0
	end
else
	#如果系统库目录,则在系统库中寻找
	$LOAD_PATH.each do |path|
		new_path = "#{path}/#{file_path}.rb"
		if File.exist?(new_path)
			out_path new_path
			exit 0
			break
		end
	end
end

#没找到,返回1
exit 1